using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class CMSG_MOVE_SET_RUN_SPEED_DEF : DefinitionBase
    {
        public override bool Process()
        {
            long current_position = base.Stream.Position;
            ProcessInternal(current_position);
            return Validate();
        }

        public override bool Process(uint pParentOpcode, uint opcode, long pPosition, long pSize)
        {
            base.SetCustomPositionAndSize(pPosition, pSize);
            ProcessInternal(pPosition);

            return ValidateMovementOpcode(pParentOpcode.ToString(), pPosition, pSize);
        }

        private void ProcessInternal(long pCurrentPosition)
        {
            base.Stream.Position = pCurrentPosition;

            MovementInfo movementInfo = new MovementInfo();

            movementInfo.guid = popGuid();
            movementInfo.movementFlags = (MovementFlags)ReadUInt32();
            if (ClientBuild >= 9183)
            {
                movementInfo.movementFlags2 = (MovementFlags2)ReadUInt16();
            }
            else
            {
                movementInfo.movementFlags2 = (MovementFlags2)ReadByte();
            }
            movementInfo.timeStamp = ReadUInt32();

            movementInfo.positionInfo = ReadCoord4();

            //UInt32 flagunk = ReadUInt32();
            movementInfo.fallTime = ReadUInt32();

            float speed = ReadSingle();

            UpdateObjectPosition(movementInfo);
        }

    }
}